using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerCatchSwordState : PlayerState
{
    Transform sword;

    public PlayerCatchSwordState(Player player, PlayerStateMachine playerStateMachine, string animBoolName) : base(player, playerStateMachine, animBoolName)
    {
    }

    public override void Enter()
    {
        base.Enter();
        sword = player.sword.transform;
        player.playerFx.ShowDastFx();
        player.playerFx.ScreenShake(player.playerFx.swordBackshakePower);
        if (sword.position.x > player.transform.position.x && player.faceDir == -1)
        {
            player.Flip();
        }
        else if (sword.position.x < player.transform.position.x && player.faceDir == 1)
        {
            player.Flip();
        }
        rb.velocity = new Vector2(player.swordReturnForce * -player.faceDir, rb.velocity.y);
    }

    public override void Exit()
    {
        base.Exit();
        player.StartCoroutine("IsBusy", .2f);
    }

    public override void Update()
    {
        base.Update();
        if (triggerCalled)
            player.playerStateMachine.ChangeState(player.playerIdleState);
    }
}
